﻿<div class="box">
    <div class="box-heading">Tìm theo</div>
    <div class="box-content">
        <ul class="box-filter">
            <li><span id="filter-group">Giá</span>
                <ul>
                    <li>
                        <input type="checkbox" class="priceSearch" value="0" />
                        <label for="filter3"><100K</label>
                    </li>
                    <li>
                        <input type="checkbox" class="priceSearch" value="1" />
                        <label for="filter4">100K - 500K</label>
                    </li>
                    <li>
                        <input type="checkbox" class="priceSearch" value="2" />
                        <label for="filter5">500K - 1M</label>
                    </li>
                    <li>
                        <input type="checkbox" class="priceSearch" value="3" />
                        <label for="filter6">>1M</label>
                    </li>
                </ul>
            </li>
        </ul>
        <a id="button-filter" class="button" onclick="Search()">Tìm kiếm</a>
    </div>
</div>

<script>
    function Search() {
        var inputCheck = $('input.priceSearch:checked');
        var price = "";
        var url;
        if (inputCheck != null && inputCheck.length!=0) {
            for (i = 0; i < inputCheck.length; i++) {
                price = price + $(inputCheck[i]).val() + "-";
            }
            price = price.substring(0, price.length - 1);

            url = $("#Url").val() + "?page=1" + "&sortOrder=" + $("#ddlSort option:selected").val() + "&price=" + price;
            window.location.href = url;
        } else {
            url = $("#Url").val() + "?page=1" + "&sortOrder=" + $("#ddlSort option:selected").val() + "&price=All";
            window.location.href = url;
        }
    }
   
    $(document).ready(function () {
        $('.priceSearch').each(function () { //loop through each checkbox
            if ($("#Price").val().indexOf($(this).val()) !=-1) {
                this.checked = true;
            } else {
                this.checked = false;
            }
        });
    });
</script>
